from contifyuser.models import Member
from contifyuser.forms import RegistrationFormConnectPeople
from django import forms
from django.conf import settings
from django import forms
import datetime
from StartGroup.models import Group
from django.contrib.auth.models import User

attrs_dict = { 'class': 'required' }

class StartGroupForm(forms.Form):
    
    group_name = forms.CharField(max_length=25, required=True, label='GIVE YOUR GROUP A NAME', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'25'}))
    group_tagline = forms.CharField(max_length=25, required=True, label='GIVE IT A SOLID TAG LINE', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'50'}))
    group_desc = forms.CharField(max_length=200, required=False, label='DESCRIBE YOUR GROUP',
                                 widget=forms.Textarea(attrs={'size':'100'}))
    group_web_address = forms.CharField(max_length=25, required=True, label='WEB ADDRESS', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'10'}))
    group_country = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='COUNTRY',
                                widget=forms.Select())
    group_zipcode = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='ZIPCODE', error_messages={'required': 'This is a required field.'},
                                widget=forms.TextInput(attrs={'size':'5'}))
    group_city = forms.CharField(max_length=25, required=True, label='GROUP CITY', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'25'}))
    group_created_date = datetime.date.today()
        
    def save(self, member_info):        
        member = member_info
        new_connectpeople_group = Group(member_user = member,
                                group_name=self.cleaned_data['group_name'],
                                group_tagline=self.cleaned_data['group_tagline'],
                                group_desc=self.cleaned_data['group_desc'],
                                group_web_address=self.cleaned_data['group_web_address'],
                                group_country=self.cleaned_data['group_country'],
                                group_zipcode=self.cleaned_data['group_zipcode'],
                                group_city=self.cleaned_data['group_city'],
                                )
        new_connectpeople_group.save()
        return new_connectpeople_group


class StartGroupFormNoMember(RegistrationFormConnectPeople):
    
    group_name = forms.CharField(max_length=25, required=True, label='GIVE YOUR GROUP A NAME', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'25'}))
    group_tagline = forms.CharField(max_length=25, required=True, label='GIVE IT A SOLID TAG LINE', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'50'}))
    group_desc = forms.CharField(max_length=200, required=False, label='DESCRIBE YOUR GROUP',
                                 widget=forms.Textarea(attrs={'size':'100'}))
    group_web_address = forms.CharField(max_length=25, required=True, label='WEB ADDRESS', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'10'}))
    group_country = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='COUNTRY',
                                widget=forms.Select())
    group_zipcode = forms.ChoiceField(required=False, choices=settings.COUNTRIES, label='ZIPCODE', error_messages={'required': 'This is a required field.'},
                                widget=forms.TextInput(attrs={'size':'5'}))
    group_city = forms.CharField(max_length=25, required=True, label='GROUP CITY', error_messages={'required': 'This is a required field.'},
                                 widget=forms.TextInput(attrs={'size':'25'}))
    group_created_date = datetime.date.today()
        
    def save(self):
        new_member = super(StartGroupFormNoMember, self).save()
        new_connectpeople_group = Group(member_user = new_member,
                                group_name=self.cleaned_data['group_name'],
                                group_tagline=self.cleaned_data['group_tagline'],
                                group_desc=self.cleaned_data['group_desc'],
                                group_web_address=self.cleaned_data['group_web_address'],
                                group_country=self.cleaned_data['group_country'],
                                group_zipcode=self.cleaned_data['group_zipcode'],
                                group_city=self.cleaned_data['group_city'],
                                )
        new_connectpeople_group.save()
        return new_connectpeople_group